﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

public partial class Linq_MyLinq_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DeferredQueryEvaluation();
        }
    }

    /// <summary>
    /// Linq 延迟查询
    /// </summary>
    private void DeferredQueryEvaluation()
    {
        int[] numbers = { 1, 2, 3 };
        var query = from n in numbers
                    select Square(n);

        //foreach (var n in query.ToList())
        foreach (var n in query)
            Response.Write(n.ToString() + "<br>");
    }
    private double Square(double n)
    {
        StringBuilder str = new StringBuilder();
        str.Append("Computing Square("+ n +") ... ");
        str.Append("<br />");
        //divLinq.InnerHtml += str.ToString();
        Response.Write(str.ToString());
        return Math.Pow(n, 2);
    }

}
